package com.example.ycdyus.dailyfruit.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.ycdyus.dailyfruit.R;
import com.example.ycdyus.dailyfruit.constant.URLConstant;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.HttpHandler;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;

/**
 * A simple {@link Fragment} subclass.
 */
public class TuijianFragment extends Fragment {
    private HttpHandler handler;
    private HttpUtils httpUtils;

    public TuijianFragment() {
        httpUtils = new HttpUtils();
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        initData();
        return inflater.inflate(R.layout.fragment_tuijian, container, false);
    }

    private void initData() {
        handler = httpUtils.send(HttpRequest.HttpMethod.POST, URLConstant.BAIKE_TUIJIAN_POST, getRequestParams(), new RequestCallBack() {
            @Override
            public void onSuccess(ResponseInfo responseInfo) {
                Log.e("","");
            }

            @Override
            public void onFailure(HttpException e, String s) {

            }
        });
    }

    private RequestParams getRequestParams(){
        RequestParams params = new RequestParams();
        params.addBodyParameter("limit","20");
        params.addBodyParameter("timestamp","1445516472");
        params.addBodyParameter("sec_id","");
        params.addBodyParameter("platform","ANDROID");
        params.addBodyParameter("source","app");
        params.addBodyParameter("page","1");
        params.addBodyParameter("connect_id","161c2ae532723d329ee711d284a1b36e");
        params.addBodyParameter("region_id","106092");
        params.addBodyParameter("service","bake.getArticleList");
        params.addBodyParameter("device_id","1b8ba62bf241cee5b8c317d07c0c503e");
        params.addBodyParameter("channel","portal");
        params.addBodyParameter("version","3.0.3");
        return params;
    }

    @Override
    public void onStop() {
        super.onStop();
        if(handler!=null){
            handler.cancel();
        }
    }
}
